//
//  PywPayPwdFooterView.m
//  PywSdk
//
//  Created by smallwave on 16/8/17.
//  Copyright © 2016年 zero. All rights reserved.
//

#import "PywPayPwdFooterView.h"
#import "UIButton+Pyw.h"
#import "PywMasonry.h"

@interface PywPayPwdFooterView ()

@property (nonatomic, strong) UIButton  *button; // 立即设置按钮
@property (nonatomic, copy) NSString    *title;  // 设置button的标题

@end

@implementation PywPayPwdFooterView

#pragma mark - override
- (instancetype)initWithFrame:(CGRect)frame
                     Delegate:(id<PywPayPwdFooterViewDelegate>)delegate
                  ButtonTitle:(NSString *)title{
    self = [super initWithFrame:frame];
    if (self) {
        self.delegate = delegate;
        self.title = title;
        [self setUp];
    }
    return self;
}
#pragma mark - prepareUI
- (void)setUp{
    self.backgroundColor = [UIColor clearColor];
    [self addSubviewAndLayoutSubviews];
}
- (void)addSubviewAndLayoutSubviews{
    [self addSubview:self.button];
    
    __weak typeof(self) wSelf = self;
    [self.button mas_makeConstraints:^(PywMASConstraintMaker *make) {
        make.centerX.offset(0);
        make.top.equalTo(wSelf.mas_top).offset(40);
        make.width.equalTo(wSelf.mas_width).multipliedBy(0.9);
        make.height.equalTo(@40);
    }];
}
#pragma mark - Action
- (void)buttonAction:(UIButton *)btn{
    if ([self.delegate respondsToSelector:@selector(payPwdFooterView:didSelectedButton:)]) {
        [self.delegate payPwdFooterView:self didSelectedButton:btn];
    }
}
#pragma mark - Lazy
- (UIButton *)button{
    if (!_button) {
        _button = [UIButton buttonWithBackgroundColor:RGB(252, 177, 14, 1)
                                         cornerRadius:20
                                           titleColor:[UIColor whiteColor]
                                   titleLabelFontSize:18
                                                title:self.title];
        
        [_button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _button;
}

@end
